package com.glsc.ngateway.oaflow.controller;


import com.glsc.ngateway.common.api.oaflow.resp.OaflowResponse;
import com.glsc.ngateway.common.base.domain.mysql.gateway.oaflow.TOtcSenderFilesDetail;
import com.glsc.ngateway.common.base.repo.mysql.gateway.oaflow.TOtcSenderFilesDetailRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;


@RestController
@RequestMapping("otc")
public class OtcFileController {

    @Autowired
    TOtcSenderFilesDetailRepository repository;

    @RequestMapping(value = "getSenderFilesDetailByName")
    public OaflowResponse<Map<String, Object>> getSenderFilesDetailByName(@RequestParam("fileName") String fileName) {

        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.put(OaflowResponse.groupId, fileName);

        Optional<TOtcSenderFilesDetail> dbrec = repository.findByGroupId(fileName);
        if (dbrec.isPresent()) {
            dataMap.put(OaflowResponse.isReturn, dbrec.get().getIsReturn().ordinal());
        } else {
            dataMap.put(OaflowResponse.isReturn, TOtcSenderFilesDetail.IsReturn.未反馈.ordinal());
        }

        return OaflowResponse.successData(dataMap);
    }


}
